#define _CRT_SECURE_NO_WARNINGS 1

#include<iostream>
//https://www.luogu.com.cn/problem/CF347B
using namespace std;
int n;
const int N = 1e5 + 10;
int a[N];
int p = 0;
int main()
{
	cin >> n;

	for (int i = 0; i < n; ++i)
	{
		cin >> a[i];
		if (a[i] == i)++p;
	}


	if (p == n)
	{
		cout << p << endl;
		return 0;
	}

	for (int i = 0; i < n; ++i)
	{
		if (a[i] != i && a[a[i]] == i)
		{
			cout << p + 2 << endl;
			return 0;
		}
	}

	cout << p + 1 << endl;

	return 0;
}